package com.young.jpademo2.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfigure {

    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("A");
    }

    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("B");
    }

    //配置了Swagger的Docket的Bean 实例
    @Bean
    public Docket docket(Environment environment){

        //设置要显示的swagger环境
        //Profiles profiles=Profiles.of("dev");

        //通过environment.acceptsProfiles去判断是否处在自己设置的环境中
        //boolean flag=environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("young")
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.young.jpademo2.controller"))
                //.paths(PathSelectors.ant("/young/**"))
                .build();
    }

    //配置swagger信息
    private ApiInfo apiInfo(){

        //作者信息
        Contact contact= new Contact("羊永兵", "http://localhost/young", "1763108660@qq.com");
        return new ApiInfo("YoungWorld",
                " swagger Test",
                "V1.0", "http://localhost:8080/api",
                 contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                 new ArrayList());
    }
}
